package com.shangcheng.server.controller;

import com.shangcheng.model.domain.OmsOrderReturnApply;
import com.shangcheng.model.dto.OmsOrderReturnApplyAndOmsCompanyAddress;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author JavaClimber
 * @version 1.0
 * @date 2022/5/14 0014 zihao
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    //分页查询退货申请
    @GetMapping("/list")
    public ResponseEntity lists(@RequestParam Map<String, String> map, @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "5") Integer pageSize) {
        PageResult pageResult = omsOrderReturnApplyService.lists(map, pageNum, pageSize);
        return ResponseEntity.ok(new Result(200, pageResult, "成功❗"));
    }

    //修改退货申请状态
    @PostMapping("/update/status/{id}")
    public ResponseEntity updateById(@PathVariable String id, @RequestBody OmsOrderReturnApply omsOrderReturnApply) {
        boolean b = omsOrderReturnApplyService.updateByIds(id, omsOrderReturnApply);
        if (b){
            return ResponseEntity.ok(new Result(200, "", "成功❗"));
        }else {
            return ResponseEntity.ok(new Result(403, "", "❗数值超过实际支付价格❗"));
        }
        
    }

    //获取退货申请详情
    @GetMapping("{id}")
    public ResponseEntity getByIds(@PathVariable Long id) {
        OmsOrderReturnApplyAndOmsCompanyAddress byIds = omsOrderReturnApplyService.getByIds(id);

        return ResponseEntity.ok(new Result(200, byIds, "成功❗"));
    }

    //批量删除退货申请
    @PostMapping("/delete")
    public ResponseEntity deletes(Long[] ids) {
        omsOrderReturnApplyService.deletes(ids);
        return ResponseEntity.ok(new Result(200, "", "成功❗"));
    }


}
